package com.jun.flower.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jun.flower.bean.TbBuycar;
import com.jun.flower.bean.TbBuycarExample;
import com.jun.flower.bean.TbBuycarExample.Criteria;
import com.jun.flower.dao.TbBuycarMapper;
import com.jun.flower.service.BuyCarService;

@Service
public class BuyCarServiceImpl implements BuyCarService {
	@Autowired
	private TbBuycarMapper buycarMapper;

	@Override
	public void addBuyCar(Integer flowersId, Integer userId) {
		TbBuycar buycar = new TbBuycar();
		buycar.setUserId(userId);
		buycar.setFlowersId(flowersId);
		buycarMapper.insert(buycar);
	}

	@Override
	public boolean checkBuyCar(Integer flowersId, Integer userId) {
		TbBuycarExample example = new TbBuycarExample();
		Criteria criteria = example.createCriteria();
		criteria.andFlowersIdEqualTo(flowersId);
		criteria.andUserIdEqualTo(userId);
		
		List<TbBuycar> list = buycarMapper.selectByExample(example);
		if(list != null && list.size()!=0) {
			return false;
		}
		return true;
	}

	@Override
	public List<TbBuycar> showBuyCar(Integer userId) {
		TbBuycarExample example = new TbBuycarExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		List<TbBuycar> list = buycarMapper.selectByExample(example);
		return list;
	}

	@Override
	public void deleteBuyCar(Integer flowersId, Integer userId) {
		TbBuycarExample example = new TbBuycarExample();
		Criteria criteria = example.createCriteria();
		criteria.andFlowersIdEqualTo(flowersId);
		criteria.andUserIdEqualTo(userId);
		buycarMapper.deleteByExample(example);
	}
	
	
}
